package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import pojo.Manager;
import pojo.OrderDto;

public class ReletDao {
	public ReletDao(){
		
	}
	public String  selectMoney(String roomNum){
		ConnectDao connectDao = new ConnectDao();
		String money = null;
		String sql = "SELECT money FROM room WHERE roomNum = '"+roomNum+"'";
		try{
			ResultSet rs = connectDao.stat.executeQuery(sql);
			while(rs.next()){
				money = rs.getString("money");
				break;
			}
			connectDao.closeConnect();
			return money;
		}catch(SQLException e){
			e.printStackTrace();
			connectDao.closeConnect();
			return null;
		}
		
	}
	
	public String  selectOrderId(String roomNum){
		ConnectDao connectDao = new ConnectDao();
		String orderId = null;
		String sql = "SELECT orderId FROM lives WHERE roomNum ='"+roomNum+"' AND status = '1'";
		try{
			ResultSet rs = connectDao.stat.executeQuery(sql);
			while(rs.next()){
				orderId = rs.getString("orderId");
				break;
			}
			connectDao.closeConnect();
			return orderId;
		}catch(SQLException e){
			e.printStackTrace();
			connectDao.closeConnect();
			return null;
		}
	}
	
	public OrderDto  selectOrder(String orderId){
		ConnectDao connectDao = new ConnectDao();
		String sql = "SELECT prepay,total FROM billOrder WHERE orderId = '"+orderId+"'";
		OrderDto order = null;
		try{
			ResultSet rs = connectDao.stat.executeQuery(sql);
			while(rs.next()){
				order = new OrderDto();
				order.prePay = rs.getString("prepay");
				order.total = rs.getString("total");
			}
			connectDao.closeConnect();
			return order;
		}catch(SQLException e){
			e.printStackTrace();
			connectDao.closeConnect();
			return null;
		}
	}
	
	public void updateOrder(OrderDto order){
		String orderId = order.orderId;
		String prepay = order.prePay;
		String total = order.total;
		ConnectDao connectDao = new ConnectDao();
		String sql = "UPDATE billOrder SET total = '"+total+"',prepay = '"+prepay+"' WHERE orderId ='"+orderId+"'";
		try{
			connectDao.stat.executeUpdate(sql);
			connectDao.closeConnect();
		}catch(SQLException e){
			e.printStackTrace();
			connectDao.closeConnect();
		}
	}
	
}






